import {
    createRouter,
    createWebHistory,
    RouteLocationRaw,
    stringifyQuery,
} from 'vue-router';
import { routerGuard } from './guard';
import routes from './routes';

const BASE_URL = import.meta.env.BASE_URL;

const router = createRouter({
    history: createWebHistory(BASE_URL),
    routes,
});
routerGuard(router);
function pushOverriding(to: RouteLocationRaw): any {
    if (typeof to === 'string') {
        window.open(to, '_blank');
    } else {
        const queryString = to.query ? `?${stringifyQuery(to.query)}` : '';
        window.open(`${to.path}${queryString}`, '_blank');
    }
    return;
}
router.push = pushOverriding;
export default router;
